package com.boat.starter.pulsar.core;

import com.boat.starter.pulsar.properties.PulsarProperties;

import cn.hutool.core.util.StrUtil;

/**
 * topic factory
 *
 * @author: zuomin (myleszelic@outlook.com)
 * @date: 2021/07/21-15:13
 */
public class PulsarTopicFactory {

    /** topic格式为 persistent://租户ID/命名空间/Topic名称 */
    private static final String TOPIC_PATTERN = "persistent://%s/%s/%s";

    private PulsarProperties pulsarProperties;

    public PulsarTopicFactory(PulsarProperties pulsarProperties) {
        this.pulsarProperties = pulsarProperties;
    }

    public void setTdmqProperties(PulsarProperties pulsarProperties) {
        this.pulsarProperties = pulsarProperties;
    }

	public String obtainFullTopic(String topic) {
		if (StrUtil.isBlank(pulsarProperties.getTenant()) || StrUtil.isBlank(pulsarProperties.getNamespace())) {
			return topic;
		}

		return String.format(TOPIC_PATTERN, pulsarProperties.getTenant(), pulsarProperties.getNamespace(), topic);
	}
}
